﻿<div class="main01" id="main">
    <div class="content clearfix">
        <div class="headline02">
            <div class="line_left">
                积分规则管理
            </div>
            <div class="line_right">
                <ul class="nav_line_right">
                    <li class="con"><a href="#">首页</a></li>
                    <li>/</li>
                    <li class="con"><a href="javascript:;">积分规则管理</a></li>
                </ul>
            </div>
        </div>
        <div class="bton">
            <div class="bton_left">
                <div class="bton_left_nav">
                    <a href="javascript:;" class="btn_add last">添加</a>
                </div>
            </div>
            <div class="bton_right">
                <div class="search">
                    <input type="text" name="keyWord" id="keyWord" class="sinput" placeholder="请输入搜索关键字" autofocus="" x-webkit-speech="" maxlength="50">                
                    <input type="submit" value="搜索" class="sbtn searchRule">
                </div>
            </div>
        </div>
    </div>
    <div class="tab_warp">
        <table class="sub_table" id="ruleList">
            <thead>
                <tr class="info_title">
					<th style="width: 60px;">序号</th>
					<th style="width: 200px;">行为标识</th>
					<th style="width: 240px;" class="mid_line">触发行为</th>
					<th style="width: 130px" class="mid_line">积分</th>
					<th style="width: 130px" class="mid_line">启用状态</th>
					<th style="width: 90px" class="mid_line">编辑</th>
                </tr>
            </thead>
            <tbody>
                <tr class="info_cont dis_n" kk-template="true" kk-repeat="rule in ruleList">
                    <td kk-bind="rule.order" kk-replaceDom="true"></td>
                    <td kk-bind="rule.F_PointCode" kk-replaceDom="true"></td>
                    <td kk-bind="rule.F_PointAction" kk-replaceDom="true"></td>
                    <td kk-bind="rule.F_Point" kk-replaceDom="true"></td>
                    <td >
						<div kk-if = 'rule.F_Status=="1"'>
							<div class="icon_oa color_green">已启用</div>
						</div>
						<div kk-if = 'rule.F_Status=="0"'>未启用</div>
					</td>
                    <td>
                        <div class="hide">
                            <a href="" class="btn btn-info modify_btn" kk-attr=' "data-id" : "rule.Kid" '>修改</a>
							<a href="" class="btn btn-danger delete_btn"  kk-attr=' "data-id" : "rule.Kid" '>删除</a>
                        </div>
                    </td>
                </tr>
            </tbody>
        </table>
        <!--放置分页 begin -->
        <table class="pageTable">
            <tr>
                <td colspan="15">
                    <div class="pageIn"></div>
                </td>
            </tr>
        </table>
        <!--放置分页 end -->
    </div>
    <!--弹框区域 begin-->
	<!-- 添加规则弹窗 -->
    <div id="addRuleBox" class="dialogContent" style="display:none">
        <div class="mod">
            <form action="" id="addRuleForm">
				<table border="0" class="fromtab1">
				<tr>
					<th>触发行为：&nbsp;</th>
					<td>
						<input type="text" class="inpall inp329 PointAction" id="AddPointAction" name="PointAction" 
						placeholder="触发行为" maxlength="100" kk-attr=' "value" : "addRule.PointAction"'/>
					</td>
				</tr>
				<tr>
					<th>行为标识：&nbsp;</th>
					<td>
						<input type="text" class="inpall inp329 PointCode" id="AddPointCode" name="PointCode" 
						placeholder="行为标识（例如：weixin.allocation.intent.log）" maxlength="100" kk-attr=' "value" : "addRule.PointCode"'/>
					</td>
				</tr>
				<tr>
					<th>积分：&nbsp;</th>
					<td>
						<input type="text" class="inpall inp329 Point" id="AddPoint" name="Point" placeholder="设置获得的积分" kk-attr=' "value" : "addRule.Point"'/>
					</td>
				</tr>
				<tr>
					<th>排序：&nbsp;</th>
					<td>
						<input type="text" class="inpall inp329 Sort" id="AddSort" name="Sort" placeholder="设置规则显示的优先级，1为最高" kk-attr=' "value" : "addRule.Sort"' />
					</td>
				</tr>
				<tr>
					<th>&nbsp;</th>
					<td>
						<label class="lab112"><input type="checkbox"  id="AddStatus" name="Status"/>&nbsp;&nbsp;启用</label>
					</td>
				</tr>
				<tr>
					<th>&nbsp;</th>
					<td>
						<div class="sinput" style="padding-left: 25px;">
							<input type="button" class="btn btn-warning ok" value="确 定"/>
							<input type="button" class="btn cancel" value="取 消">
						</div>
					</td>
				</tr>
			</table>
            </form>
        </div>
    </div>
	<!-- 修改规则弹窗 -->
	<div id="modifyRuleBox" class="dialogContent" style="display:none">
        <div class="mod">
            <form action="" id="modifyRuleForm">
				<input type="hidden" kk-attr=' "value" : "modifyRule.pointRuleKid"' name="pointRuleKid"/>
				<table border="0" class="fromtab1">
				<tr>
					<th>触发行为：&nbsp;</th>
					<td>
						<input type="text" class="inpall inp329 PointAction" id="ModifyPointAction" name="PointAction" 
						placeholder="触发行为" maxlength="100" kk-attr=' "value" : "modifyRule.pointAction"'/>
					</td>
				</tr>
				<tr>
					<th>行为标识：&nbsp;</th>
					<td>
						<input type="text" class="inpall inp329 PointCode" id="ModifyPointCode" name="PointCode" 
						placeholder="行为标识（例如：weixin.allocation.intent.log）" maxlength="100" kk-attr=' "value" : "modifyRule.pointCode"'/>
					</td>
				</tr>
				<tr>
					<th>积分：&nbsp;</th>
					<td>
						<input type="text" class="inpall inp329 Point" id="ModifyPoint" name="Point" placeholder="设置获得的积分" 
						value="0" max="6" kk-attr=' "value" : "modifyRule.point"'/>
					</td>
				</tr>
				<tr>
					<th>排序：&nbsp;</th>
					<td>
						<input type="text" class="inpall inp329 Sort" id="ModifySort" name="Sort" placeholder="设置规则显示的优先级，1为最高" 
						value="0" max="999" kk-attr=' "value" : "modifyRule.sort"'/>
					</td>
				</tr>
				<tr>
					<th>&nbsp;</th>
					<td>
						<label class="lab112"><input type="checkbox" name="Status" id="ModifyStatus" kk-attr=' "value" : "modifyRule.status"' >&nbsp;&nbsp;启用</label>
					</td>
				</tr>
				<tr>
					<th>&nbsp;</th>
					<td>
						<div class="sinput" style="padding-left: 25px;">
							<input type="button" class="btn btn-warning ok" value="确 定"/>
							<input type="button" class="btn cancel" value="取 消">
						</div>
					</td>
				</tr>
			</table>
            </form>
        </div>
    </div>
    <!--弹框区域 end-->
</div>
<script type="text/javascript" src="Scripts/js/pointrule.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
		//列表
		$pointrule.getList({
				dom : "#ruleList tbody"
			});
        $("#ruleList").on("click",".delete_btn",function(){
            var id = $(this).attr("data-id");
            $.messager.confirm("是否要删除",function(){
                $pointrule.deleteRule(id,"#ruleList tbody");
            },"");
            return false;
        }).on("click",".modify_btn",function(){
            var index = $(this).closest("tr").index();
            $kk.$scope.modifyRule = {
                pointRuleKid : $kk.$scope.ruleList[index].Kid,
                pointCode : $kk.$scope.ruleList[index].F_PointCode,
                pointAction :  $kk.$scope.ruleList[index].F_PointAction,
				status : $kk.$scope.ruleList[index].F_Status,
				point : $kk.$scope.ruleList[index].F_Point,
				sort : $kk.$scope.ruleList[index].F_Sort
            };
            $kk.fillData_new("#modifyRuleForm");
			if($kk.$scope.modifyRule.status==0){				
				$("#ModifyStatus").prop("checked",false);
			}else{
				$("#ModifyStatus").prop("checked",true);
			}
            $.messager.dialog("修改","modifyRuleBox",490);
            return false;
        }).on("mouseenter","tbody>tr",function(){
            $(this).find("td:last div.hide").toggleClass("hide");
        }).on("mouseleave","tbody>tr",function(){
            $(this).find("td:last div").toggleClass("hide");
        });
        /*修改*/
        $("#modifyRuleBox").on("click",".cancel",function(){
            $.dialog.get["modifyRuleBox"].hide();
        });
        $("#modifyRuleBox").on("click",".ok",function(){
            $pointrule.modifyRule($("#modifyRuleForm").serialize(),"#ruleList tbody");
            $.dialog.get["modifyRuleBox"].hide();
        });
        /*添加*/
        $(".btn_add").on("click",function(){
			$kk.$scope.addRule = {
                PointAction : "",
                PointCode :  "",
				Point : "",
				Sort: "" ,
				Status : 0,
            };
			$kk.fillData_new("#addRuleForm");
			$("#AddStatus").prop("checked",false);
            $.messager.dialog("添加","addRuleBox",490);
        });
        $("#addRuleBox").on("click",".cancel",function(){
            $.dialog.get["addRuleBox"].hide();
        });
        $("#addRuleBox").on("click",".ok",function(){
            $pointrule.addRule($("#addRuleForm").serialize(),"#ruleList tbody");
            $.dialog.get["addRuleBox"].hide();
        });
		
		//搜索
        $(".searchRule").on("click",function(){
            var kw = $("#keyWord").val();
            $pointrule.searchRule("#ruleList tbody",kw);
        })
		
		//添加，checkbox
		$("#AddStatus").on("click",function(){
			var status = this.checked?1:0;
			$(this).val(status);
		})
		
		//修改，checkbox
		$("#ModifyStatus").on("click",function(){
			var status = this.checked?1:0;
			$(this).val(status);
		})
    })
</script>